from fenrispunk_tools.config import get_sprite_length


def get_tile_sprite(tile_origin: tuple, sprite_length: int) -> tuple:
    return get_rect(tile_origin, sprite_length)


def get_tile(value: str, sprite_length: int) -> tuple:
    return get_tile_dict().get(value, get_tile_default)(sprite_length=sprite_length)


def get_rect(origin: tuple, sprite_length: int) -> tuple:
    """Rect(left, top, width, height)"""
    x_off, y_off = origin
    return (x_off * sprite_length, y_off * sprite_length, sprite_length, sprite_length)


def get_tile_dict() -> dict:
    return {
        " ": get_tile_space,
        "!": get_tile_object_magical,
        '"': get_tile_default,
        "#": get_tile_wall,
        "$": get_tile_object_valuable,
        "%": get_tile_cover_large,
        "&": get_tile_npc,
        "'": get_tile_door_open,
        "(": get_tile_default,
        ")": get_tile_default,
        "*": get_tile_goal,
        "+": get_tile_door_closed,
        ",": get_tile_default,
        "-": get_tile_cover_opaque,
        ".": get_tile_floor,
        "/": get_tile_door_above,
        0: get_tile_default,
        1: get_tile_default,
        2: get_tile_default,
        3: get_tile_default,
        4: get_tile_default,
        5: get_tile_default,
        6: get_tile_default,
        7: get_tile_default,
        8: get_tile_default,
        9: get_tile_default,
        ":": get_tile_cover_solid,
        ";": get_tile_floor_alt,
        "<": get_tile_stairs_up,
        "=": get_tile_water,
        ">": get_tile_stairs_down,
        "?": get_tile_chest,
        "@": get_tile_pc,
        "A": get_tile_default,
        "B": get_tile_default,
        "C": get_tile_default,
        "D": get_tile_default,
        "E": get_tile_default,
        "F": get_tile_default,
        "G": get_tile_default,
        "H": get_tile_default,
        "I": get_tile_default,
        "J": get_tile_default,
        "K": get_tile_default,
        "L": get_tile_default,
        "M": get_tile_default,
        "N": get_tile_default,
        "O": get_tile_default,
        "P": get_tile_default,
        "Q": get_tile_default,
        "R": get_tile_default,
        "S": get_tile_default,
        "T": get_tile_default,
        "U": get_tile_default,
        "V": get_tile_default,
        "W": get_tile_default,
        "X": get_tile_default,
        "Y": get_tile_default,
        "Z": get_tile_default,
        "[": get_tile_wall_hollow,
        "\\": get_tile_lift,
        "]": get_tile_wall_hollow2,
        "^": get_tile_trap,
        "_": get_tile_wall_narrow,
        "`": get_tile_default,
        "a": get_tile_default,
        "b": get_tile_default,
        "c": get_tile_default,
        "d": get_tile_default,
        "e": get_tile_default,
        "f": get_tile_default,
        "g": get_tile_default,
        "h": get_tile_default,
        "i": get_tile_default,
        "j": get_tile_default,
        "k": get_tile_default,
        "l": get_tile_default,
        "m": get_tile_default,
        "n": get_tile_default,
        "o": get_tile_default,
        "p": get_tile_default,
        "q": get_tile_default,
        "r": get_tile_default,
        "s": get_tile_default,
        "t": get_tile_default,
        "u": get_tile_default,
        "v": get_tile_default,
        "w": get_tile_default,
        "x": get_tile_default,
        "y": get_tile_default,
        "z": get_tile_floor_loose,
        "{": get_tile_default,
        "|": get_tile_default,
        "}": get_tile_default,
        "~": get_tile_object,
        "": get_tile_default,  # use DEL for default
    }


# ---------- ROW 1 ----- --------- ---------- ----------


def get_tile_space(origin=(0, 0), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_object_magical(origin=(1, 0), sprite_length=get_sprite_length()):
    return get_tile_sprite(origin, sprite_length)


def get_tile_wall(origin=(3, 0), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_object_valuable(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_cover_large(origin=(5, 0), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_npc(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_door_open(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_goal(origin=(10, 0), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_door_closed(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_cover_opaque(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_floor(origin=(14, 0), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_door_above(origin=(15, 0), sprite_length=get_sprite_length()):
    return get_tile_default()


# ---------- ROW 2 ----- --------- ---------- ----------


def get_tile_cover_solid(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_floor_alt(origin=(11, 1), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_stairs_up(origin=(12, 1), sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_water(origin=(13, 1), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_stairs_down(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_chest(origin=(15, 1), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


# ---------- ROW 3 ----- --------- ---------- ----------


def get_tile_pc(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


# ---------- ROW 4 ----- --------- ---------- ----------


def get_tile_wall_hollow(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_lift(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_wall_hollow2(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_trap(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_wall_narrow(origin=None, sprite_length=get_sprite_length()):
    return get_tile_wall()


# ---------- ROW 5 ----- --------- ---------- ----------
# ---------- ROW 6 ----- --------- ---------- ----------


def get_tile_floor_loose(origin=(15, 5), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)


def get_tile_object(origin=None, sprite_length=get_sprite_length()):
    return get_tile_default()


def get_tile_default(origin=(15, 5), sprite_length=get_sprite_length()) -> tuple:
    return get_tile_sprite(origin, sprite_length)
